package com.situ.mall.common.handler;

import com.situ.mall.common.exception.BusinessException;
import com.situ.mall.common.exception.NoLoginException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(NoLoginException.class)
    public ResponseEntity handler2(NoLoginException e){
        return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(null);
    }

    @ExceptionHandler(BusinessException.class)
    public ResponseEntity<Map<String,String>>handler1(BusinessException e){
        Map<String,String> map = new HashMap<>();
        map.put("msg",e.getMsg());
        return  ResponseEntity.status( HttpStatus.INTERNAL_SERVER_ERROR).body(map);
    }
}
